package com.jike.noobmoney.mvp.view.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.mvp.presenter.AppPresenter;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.util.SPUtils;
import com.jike.noobmoney.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;


public class FeedBackActivity extends BaseActivity implements IView {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.et_feedback)
    EditText etFeedback;
    @BindView(R.id.et_phone)
    EditText etPhone;
    private AppPresenter appPresenter;
    private String userid;

    @Override
    protected int layoutResID() {
        return R.layout.activity_feed_back;
    }

    @Override
    protected void initData() {
        tvTitle.setText("意见反馈");
        appPresenter = new AppPresenter(this);
        userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
    }

    @OnClick({R.id.iv_back, R.id.tv_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_submit:
                submit();
                break;
        }
    }

    /**
     * 提交
     */
    private void submit() {
        String feedback = etFeedback.getText().toString().trim();
        String phone = etPhone.getText().toString().trim();
        String newtext = TextUtils.isEmpty(phone) ? "" : "联系方式:" + phone;
        if (!TextUtils.isEmpty(feedback)) {
            showProgress();
            //网络请求
            appPresenter.feedBack(userid, feedback + newtext, ConstantValue.RequestKey.feedback);
        } else {
            ToastUtils.showShortToastSafe("请输入反馈内容");
        }

    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        dismissProgress();
        if (ConstantValue.RequestKey.feedback.equals(actionType)) {
            ToastUtils.showShortToastSafe(msg);
            finish();
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        dismissProgress();
        ToastUtils.showShortToastSafe(msg);
    }
}
